package com.hzh.spark.core
import com.hzh.util.HdfsUtil
import org.apache.spark.{SparkConf, SparkContext}

object Demo19SparkYarn {

  def main(args: Array[String]): Unit = {
    /**
     * 建立连接
     */
    val conf = new SparkConf()

    conf.setAppName("submit")

    val sc = new SparkContext(conf)
    HdfsUtil.delete("/shujia/studentout1")
    sc.textFile("/shujia/student/students.txt")
      .map(_.split(","))
      .map {
        case Array(_, _, _, _, clazz) =>
          (clazz, 1)
      }
      .reduceByKey(_ + _)
      .map {
        case (clazz: String, num: Int) =>
          s"$clazz\t$num"
      }
      .saveAsTextFile("/shujia/studentout1")
    }
}


